Data_Path=fullfile(TDMSFileFolder,TDMSFileName);

%Create the file (Always call 'DDC_CloseFile' when you are finished using a file)
filename = TDMSFileName;
filedesc = '';
filetitle = '';
fileauth = '';
fileIn = 0;
[err,dummyVar,dummyVar,dummyVar,dummyVar,dummyVar,dummyVar,file] = calllib(libname,'DDC_CreateFile',Data_Path,'',filename,filedesc,filetitle,fileauth,fileIn);

%Set the file timestamp property
c=int32(clock);
[err,dummyVar] = calllib(libname,'DDC_SetFilePropertyTimestampComponents',file,DDC_FILE_DATETIME,c(1),c(2),c(3),c(4),c(5),c(6),0);

%Add Cell Track channel group to the file
grpname = 'Cell Track';
grpdesc = 'Cell Track';
sinegrpIn = 0;
[err,dummyVar,dummyVar,celltrackgrp] = calllib(libname,'DDC_AddChannelGroup',file,grpname,grpdesc,sinegrpIn);

%Add channels to channel groups
chanunitstring = '';
cellchanIn = 0;

%Add a new data channel and add data
channame = 'time';
chandesc = '';
chandata = timeVec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'x';
chandesc = '';
chandata = xVec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'y';
chandesc = '';
chandata = yVec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'ax1';
chandesc = '';
chandata = ax1Vec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'ax2';
chandesc = '';
chandata = ax2Vec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'circularity';
chandesc = '';
chandata = circularityVec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'area';
chandesc = '';
chandata = areaVec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));

%Add a new data channel and add data
channame = 'raw area';
chandesc = '';
chandata = rawAreaVec;
[err,dummyVar,dummyVar,dummyVar,chanName] = calllib(libname,'DDC_AddChannel',celltrackgrp,'DDC_Double',channame,chandesc,chanunitstring,cellchanIn);
[err,dummyVar] = calllib(libname,'DDC_SetDataValues',chanName,chandata,length(chandata));


%Save file
err = calllib(libname,'DDC_SaveFile',file);

%Close file
err = calllib(libname,'DDC_CloseFile',file);
